package org.yoyo.classroom.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.yoyo.classroom.domain.po.LostFound;
import org.yoyo.classroom.mapper.LostFoundMapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 失物招领业务逻辑层
 */
@Service
public class LostFoundService {

    @Autowired
    private LostFoundMapper lostFoundMapper;

    /**
     * 根据ID查询失物招领信息
     * @param id 失物招领ID
     * @return 失物招领对象
     */
    public LostFound getLostFoundById(Long id) {
        return lostFoundMapper.selectById(id);
    }

    /**
     * 查询所有失物招领信息
     * @return 失物招领列表
     */
    public List<LostFound> getAllLostFounds() {
        return lostFoundMapper.selectAll();
    }

    /**
     * 插入失物招领信息
     * @param lostFound 失物招领对象
     * @return 影响的行数
     */
    public int addLostFound(LostFound lostFound) {
        return lostFoundMapper.insert(lostFound);
    }

    /**
     * 更新失物招领信息
     * @param lostFound 失物招领对象
     * @return 影响的行数
     */
    public int updateLostFound(LostFound lostFound) {
        return lostFoundMapper.update(lostFound);
    }

    /**
     * 删除失物招领信息（逻辑删除）
     * @param id 失物招领ID
     * @return 影响的行数
     */
    public int deleteLostFound(Long id) {
        return lostFoundMapper.delete(id);
    }

    public List<LostFound> getLostFoundsByCondition(String type, String status, String search, String sort) {
        Map<String, Object> params = new HashMap<>();
        params.put("type", type);
        params.put("status", status);
        params.put("search", search);
        params.put("sort", sort);
        return lostFoundMapper.selectByCondition(params);
    }
}
